package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class DepartmentDAO implements DaoInterface<Department> {
	private ArrayList<Department> arList;

	public DepartmentDAO(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {
		arList.add(item);

	}

	@Override
	public Department searchitem(Department item) {
		if (arList.contains(item)) {
			return arList.get(arList.indexOf(item));
		} else {
			return null;
		}
	}

	@Override
	public void setitem(Department item) {
		arList.set(arList.indexOf(item), item);
	}

	@Override
	public void delitem(Department item) {
		if (arList.contains(item)) {

			arList.remove(arList.indexOf(item));

		} else {
			System.out.println("해당 학과정보 음슴");
		}

	}

	@Override
	public void prnList() {
		prnHeader();
		for (Department std : arList) {
			System.out.println(std);
		}

	}

	@Override
	public void prnHeader() {
		String header = String.format("%3s\t %5s\t %3s", "학과번호", "학과명", "위치");
		System.out.println(header);
	}

}
